﻿<UserControl x:Class="Wokhan.WindowsFirewallNotifier.Console.UI.Controls.LineChart"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:local="clr-namespace:Wokhan.WindowsFirewallNotifier.Console.UI.Controls"
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300"
             DataContext="{Binding RelativeSource={RelativeSource Self}}"
             x:Name="Chart">
    <Grid>
        <DockPanel>
            <Border DockPanel.Dock="Bottom" Margin="60,0,0,0" BorderThickness="0,1,0,0" BorderBrush="Black">
                <ItemsControl ItemsSource="{Binding Xs}">
                    <ItemsControl.ItemContainerStyle>
                        <Style TargetType="ContentPresenter">
                            <Setter Property="Canvas.Top" Value="0"/>
                            <Setter Property="Canvas.Left" Value="{Binding ScaledValue}"/>
                        </Style>
                    </ItemsControl.ItemContainerStyle>
                    <ItemsControl.ItemsPanel>
                        <ItemsPanelTemplate>
                            <Canvas Height="60" ClipToBounds="True" />
                        </ItemsPanelTemplate>
                    </ItemsControl.ItemsPanel>
                    <ItemsControl.ItemTemplate>
                        <DataTemplate>
                            <StackPanel>
                                <Rectangle HorizontalAlignment="Left" Fill="Black" Height="5" Width="1" />
                                <Label Content="{Binding RealValue}" Margin="-50,-10,0,0" FontSize="11">
                                    <Label.LayoutTransform>
                                        <RotateTransform Angle="-35" />
                                    </Label.LayoutTransform>
                                </Label>
                            </StackPanel>
                        </DataTemplate>
                    </ItemsControl.ItemTemplate>
                </ItemsControl>
            </Border>
            <Border DockPanel.Dock="Left" BorderThickness="0,0,1,0" BorderBrush="Black">
                <ItemsControl ItemsSource="{Binding Ys}">
                    <ItemsControl.ItemContainerStyle>
                        <Style TargetType="ContentPresenter">
                            <Setter Property="Canvas.Bottom" Value="{Binding ScaledValue}"/>
                            <Setter Property="Canvas.Right" Value="0"/>
                        </Style>
                    </ItemsControl.ItemContainerStyle>
                    <ItemsControl.ItemsPanel>
                        <ItemsPanelTemplate>
                            <Canvas Width="60" ClipToBounds="True" />
                        </ItemsPanelTemplate>
                    </ItemsControl.ItemsPanel>
                    <ItemsControl.ItemTemplate>
                        <DataTemplate>
                            <Label Content="{Binding RealValue}" FontSize="10">
                                <Label.LayoutTransform>
                                    <RotateTransform Angle="-35" />
                                </Label.LayoutTransform>
                            </Label>
                        </DataTemplate>
                    </ItemsControl.ItemTemplate>
                </ItemsControl>
            </Border>
            <Grid>
                <ItemsControl x:Name="GridLines" ItemsSource="{Binding Ys}">
                    <ItemsControl.ItemContainerStyle>
                        <Style TargetType="ContentPresenter">
                            <Setter Property="Canvas.Bottom" Value="{Binding ScaledValue}"/>
                        </Style>
                    </ItemsControl.ItemContainerStyle>
                    <ItemsControl.ItemsPanel>
                        <ItemsPanelTemplate>
                            <Canvas />
                        </ItemsPanelTemplate>
                    </ItemsControl.ItemsPanel>
                    <ItemsControl.ItemTemplate>
                        <DataTemplate>
                            <Line StrokeThickness="1" X1="-5" X2="{Binding ActualWidth, ElementName=chartZone}" Y1="0" Y2="0" Stroke="Gray" />
                        </DataTemplate>
                    </ItemsControl.ItemTemplate>
                </ItemsControl>
                <ItemsControl x:Name="chartZone" ClipToBounds="True" Margin="0" Padding="0" ItemsSource="{Binding DataSeries}">
                    <ItemsControl.ItemsPanel>
                        <ItemsPanelTemplate>
                            <Canvas>
                                <Canvas.LayoutTransform>
                                    <ScaleTransform CenterY="0.5" ScaleY="-1" />
                                </Canvas.LayoutTransform>
                            </Canvas>
                        </ItemsPanelTemplate>
                    </ItemsControl.ItemsPanel>
                    <ItemsControl.ItemTemplate>
                        <DataTemplate>
                            <Polyline x:Name="line" StrokeStartLineCap="Round" StrokeEndLineCap="Round" StrokeThickness="2" MouseEnter="line_MouseEnter" Points="{Binding PointsCollection}" Tag="{Binding}" ToolTip="{Binding Name}" Stroke="{Binding Brush, FallbackValue=Black}">
                                <Polyline.Style>
                                    <Style TargetType="Polyline">
                                        <Style.Triggers>
                                            <DataTrigger Binding="{Binding IsSelected}" Value="True">
                                                <Setter Property="StrokeThickness" Value="3" />
                                            </DataTrigger>
                                        </Style.Triggers>
                                    </Style>
                                </Polyline.Style>
                            </Polyline>
                        </DataTemplate>
                    </ItemsControl.ItemTemplate>
                </ItemsControl>
                <!--<Line X1="{Binding CurrentX}" X2="{Binding CurrentX}" Y2="{Binding ActualHeight, ElementName=chartZone}" StrokeThickness="1" Stroke="Red">
                    <Line.LayoutTransform>
                        <TranslateTransform X="{Binding XTranslate}" />
                    </Line.LayoutTransform>
                </Line>-->
            </Grid>
        </DockPanel>
    </Grid>
</UserControl>
